import * as server from '../server/sys-setting.js'
import router from '@/router'
import Vue from 'vue'

export default {
    namespaced: true,
    state: {
        sysUser: {},
        jobId: '',
        meun: {},
        sysMenuFuncs: [],
        organization: []
    },
    mutations: {
        SET_ORGANIZATION(state, { organization }) {
            Vue.set(state, 'organization', organization)
        }
    },
    actions: {
        // 职位管理
        async getSysJobs({ commit }, { organizationId }) {
            const { result: sysJobs, total } = await server.getSysJobs(this.state.base.organizationId)
            return { sysJobs, total }
        },
        async deleteSysJobs({ dispatch, commit }, { ids }) {
            await server.deleteSysJobs(ids)
            await dispatch({ type: 'getSysJobs' })
        },
        async createSysJobs({ dispatch, commit }, { values }) {
            await server.createSysJobs(values)
            await dispatch({ type: 'getSysJobs' })
        },
        async modifySysJobs({ dispatch, commit }, { values }) {
            await server.modifySysJobs(values)
            await dispatch({ type: 'getSysJobs' })
        },
        // 组织机构管理
        // 获取组织机构
        async getOrganization({ commit }) {
            if (this.state.sysSetting.organization.length === 0) {
                const { result: organization } = await server.getOrganization()
                // commit({ type: 'SET_ORGANIZATION', organization })
                return organization
            }
        },
        async create({ dispatch }, { values, url }) {
            await server.create(url, values)
        },
        async modify({ dispatch }, { values, url }) {
            await server.modify(url, values)
        },
        async delete({ dispatch }, { ids, url }) {
            await server.deleteData(url, ids)
        },
        async getData({ commit }, { url, props }) {
            let { data: tableData } = await server.getListData(url, props)
            return tableData
        },
    },
}
